#include <iostream>
#include <unistd.h>
#include <vector>
#include "thread.hpp"

//应用方的视角
string GetThreadName()
{
    static int number = 1;
    char name[64];
    snprintf(name, sizeof(name), "Thread-%d", number++);
    return name;
}

void Print()
{
    while(true)
    {
        cout << "hello world" << endl;
        sleep(1);
    }    
}

int main()
{
    const int num = 5;
    vector<Thread> threads;
    for(int i = 0; i < num; i++)
    {
        threads.push_back(Thread(Print, GetThreadName()));
    }
    
    for(auto& t : threads)
    {
        cout << t.ThreadName() << ", is running: " << t.IsRunning() << endl;
    }

    for(auto &t : threads)
    {
        t.start();
    }

    for(auto& t : threads)
    {
        cout << t.ThreadName() << ", is running: " << t.IsRunning() << endl;
    }

    for(auto& t : threads)
    {
        t.join();
    }

    return 0;
}